<template>
  <view class="flex flex-column" :style="'height:' + screenHigth + 'px;'">
    <!-- 头部 -->
    <yHeader
      :current="0"
      :screenWidth="screenWidth"
      @Tabs="handleTabs"
    ></yHeader>
    <view class="__inner authorized p-4">
      <el-steps :active="active1" finish-status="success" align-center>
        <el-step title="选择认证方式"></el-step>
        <el-step title="填写认证信息"></el-step>
        <el-step title="成功"></el-step>
      </el-steps>
      <view class="content py-2">
        <!-- 选择 -->
        <view class="content1" v-show="active == 0">
          <view class="label"> 商家类型: </view>
          <!--  -->
          <view
            class="item"
            :class="{ active: activeIndex === 0 }"
            @click="type_method(0)"
          >
            <view class="img">
              <image src="@/static/icon/download1.png" mode="scaleToFill" />
            </view>
            <view class="item_text">
              <text>个人商家</text>
              <text>认证成为个体用户，可查看所有本平台商品最新交易情况</text>
            </view>
          </view>
          <!--  -->
          <view
            class="item"
            :class="{ active: activeIndex === 1 }"
            @click="type_method(1)"
          >
            <view class="img">
              <image src="@/static/icon/download1.png" mode="scaleToFill" />
            </view>
            <view class="item_text">
              <text>企业商家</text>
              <text
                >认证成为企业用户，参与本平台交 易、金融、物流等全部服务</text
              >
            </view>
          </view>
          <!--  -->
        </view>
        <!-- 个人认证 -->
        <view class="content2-2" v-show="active == 1 && type_index == 0">
          <el-tabs v-model="activeName" @tab-click="handleClick">
            <!--  -->
            <el-tab-pane label="实名信息" name="first">
              <el-form
                ref="form4"
                :model="enterprise_info.Children.enterprise_legal_person[0]"
                :rules="rules3"
                label-width="100px"
              >
                <el-form-item>
                  <view class="flex" style="justify-content: space-between">
                    <view>
                      <view class="preview" v-show="imageUrl">
                        <el-image
                          class="el-upload-list__item-thumbnail"
                          style="width: 148px; height: 148px"
                          :src="imageUrl"
                          fit="contain"
                        ></el-image>
                        <span class="el-upload-list__item-actions">
                          <!-- <span @click="handlePictureCardPreview(form.pic)"
                            ><i class="el-icon-zoom-in"></i
                          ></span>
                          <span @click="handleRemove('front')"
                            ><i class="el-icon-delete"></i
                          ></span> -->
                        </span>
                      </view>
                      <el-upload
                        v-show="!imageUrl"
                        class="upload-demo"
                        :show-file-list="false"
                        list-type="picture-card"
                        action=""
                        accept="image/*"
                        :before-upload="ID_card_front"
                      >
                        <i slot="default" class="el-icon-plus"></i>
                        <view class="el-upload__tip" slot="tip">
                          请上传身份证正面
                        </view>
                      </el-upload>
                    </view>
                    <view>
                      <view class="preview" v-show="imageUrl2">
                        <el-image
                          class="el-upload-list__item-thumbnail"
                          style="width: 148px; height: 148px"
                          :src="imageUrl2"
                          fit="contain"
                        ></el-image>
                        <span class="el-upload-list__item-actions">
                          <!-- <span @click="handlePictureCardPreview(form.pic)"
                            ><i class="el-icon-zoom-in"></i
                          ></span>
                          <span @click="handleRemove('front')"
                            ><i class="el-icon-delete"></i
                          ></span> -->
                        </span>
                      </view>
                      <el-upload
                        v-show="!imageUrl2"
                        class="upload-demo"
                        :show-file-list="false"
                        list-type="picture-card"
                        action=""
                        accept="image/*"
                        :before-upload="ID_card_opposite"
                      >
                        <i slot="default" class="el-icon-plus"></i>
                        <view class="el-upload__tip" slot="tip">
                          请上传身份证反面
                        </view>
                      </el-upload>
                    </view>
                  </view>
                </el-form-item>
                <el-form-item label="姓名" prop="Legal_Person">
                  <el-input
                    v-model="
                      enterprise_info.Children.enterprise_legal_person[0]
                        .Legal_Person
                    "
                    placeholder="请输入姓名"
                  ></el-input>
                </el-form-item>
                <el-form-item label="证件类型" prop="IDType">
                  <el-select
                    v-model="
                      enterprise_info.Children.enterprise_legal_person[0].IDType
                    "
                    placeholder="请选择证件类型"
                  >
                    <el-option label="身份证" value="1"></el-option>
                    <el-option
                      label="香港居民往来内地通行证"
                      value="2"
                    ></el-option>
                    <el-option
                      label="澳门居民往来内地通行证"
                      value="3"
                    ></el-option>
                    <el-option label="护照" value="4"></el-option>
                  </el-select>
                </el-form-item>
                <el-form-item label="证件号码" prop="ID_Number">
                  <el-input
                    v-model="
                      enterprise_info.Children.enterprise_legal_person[0]
                        .ID_Number
                    "
                    placeholder="请输入证件号码"
                  ></el-input>
                </el-form-item>
                <!-- <el-form-item label="是否进行溯源" prop="ID_Number">
                  <el-input
                    v-model="
                      enterprise_info.Children.enterprise_legal_person[0]
                        .ID_Number
                    "
                    placeholder="请输入证件号码"
                  ></el-input>
                </el-form-item> -->
                <el-form-item>
                  <el-button type="success" @click="previous"
                    >上一页
                  </el-button>
                  <el-button type="primary" @click="submitForm1('form4')"
                    >下一步</el-button
                  >
                </el-form-item>
              </el-form>
            </el-tab-pane>
            <el-tab-pane label="银行账户信息" name="second">
              <el-form
                ref="form5"
                :rules="rules2"
                :model="enterprise_info.Children.enterprise_account[0]"
                label-width="100px"
              >
                <el-form-item label="开户名" prop="Account_Name">
                  <el-input
                    v-model="
                      enterprise_info.Children.enterprise_account[0]
                        .Account_Name
                    "
                    placeholder="请输入开户名"
                  ></el-input>
                  <text class="tex"
                    >需要使用当前实名认证信息对应的收款账号</text
                  >
                </el-form-item>
                <el-form-item label="开户行">
                  <el-cascader
                    v-model="bank"
                    style="width: 80%"
                    :options="Banks"
                    :props="{
                      expandTrigger: 'hover',
                      label: 'name',
                      value: 'name',
                    }"
                    placeholder="请选择开户行"
                  ></el-cascader>
                </el-form-item>
                <el-form-item label="银行账号" prop="Account_Number">
                  <el-input
                    v-model="
                      enterprise_info.Children.enterprise_account[0]
                        .Account_Number
                    "
                    placeholder="请输入银行账号"
                  ></el-input>
                </el-form-item>
                <el-form-item>
                  <el-button type="primary" @click="previousPage(1)"
                    >上一步</el-button
                  >
                  <el-button type="primary" @click="nextPage1('form5')"
                    >下一步</el-button
                  >
                </el-form-item>
              </el-form>
            </el-tab-pane>
            <el-tab-pane label="联系方式" name="third">
              <el-form
                ref="form6"
                :model="enterprise_info"
                :rules="rules1"
                label-width="100px"
              >
                <el-form-item label="地址" prop="address">
                  <el-cascader
                    placeholder="请选择地址"
                    v-model="address"
                    style="width: 80%"
                    :options="Address"
                    :props="{
                      expandTrigger: 'hover',
                      label: 'text',
                      value: 'text',
                      children: 'children',
                    }"
                  ></el-cascader>
                </el-form-item>
                <el-form-item label="详细地址" prop="Enterprise_Address">
                  <el-input
                    v-model="enterprise_info.Enterprise_Address"
                    placeholder="请输入详细地址"
                  ></el-input>
                </el-form-item>
                <el-form-item label="邮箱" prop="E_Mail">
                  <el-input
                    v-model="enterprise_info.E_Mail"
                    placeholder="请输入邮箱"
                  ></el-input>
                </el-form-item>
                <el-form-item label="手机号">
                  <el-input
                    v-model="
                      enterprise_info.Children.enterprise_legal_person[0].Mobile
                    "
                    placeholder="请输入手机号"
                  ></el-input>
                </el-form-item>
                <el-form-item label="验证码" prop="Code">
                  <view class="flex align-center">
                    <el-input
                      v-model="
                        enterprise_info.Children.enterprise_legal_person[0].Code
                      "
                      placeholder="请输入验证码"
                    ></el-input>
                    <el-button v-if="time" @click="sendMessage()" type="success"
                      >获取验证码</el-button
                    >
                    <el-button v-else type="success">{{ secend }}</el-button>
                  </view>
                </el-form-item>
                <el-form-item>
                  <el-button type="primary" @click="previousPage(2)"
                    >上一页</el-button
                  >
                  <el-button
                    :loading="loading"
                    type="primary"
                    @click="submitForm3('form6')"
                    >提交</el-button
                  >
                </el-form-item>
              </el-form>
            </el-tab-pane>
          </el-tabs>
        </view>
        <!-- 企业认证 -->
        <view class="content2-2" v-show="active == 1 && type_index == 1">
          <el-tabs v-model="activeName" @tab-click="handleClick">
            <!--  -->
            <el-tab-pane label="企业信息" name="first">
              <el-form
                ref="form1"
                :model="enterprise_info"
                :rules="rules1"
                label-width="150px"
              >
                <el-form-item>
                  <!-- 请上传营业执照 -->
                  <div class="preview" v-show="src">
                    <el-image
                      class="el-upload-list__item-thumbnail"
                      style="width: 148px; height: 148px"
                      :src="Domain_Business + src"
                      fit="contain"
                    ></el-image>
                    <span class="el-upload-list__item-actions">
                      <!-- <span @click="handlePictureCardPreview(form.pic)"
                        ><i class="el-icon-zoom-in"></i
                      ></span>
                      <span @click="handleRemove('front')"
                        ><i class="el-icon-delete"></i
                      ></span> -->
                    </span>
                  </div>
                  <el-upload
                    v-show="!src"
                    class="upload-demo"
                    :show-file-list="false"
                    list-type="picture-card"
                    action=""
                    accept="image/*"
                    :before-upload="business_license"
                  >
                    <i slot="default" class="el-icon-plus"></i>
                    <view class="el-upload__tip" slot="tip">
                      请上传企业营业执照
                    </view>
                  </el-upload>
                </el-form-item>
                <el-form-item label="企业全称" prop="Enterprise_Name">
                  <el-input
                    @blur="blur"
                    v-model="enterprise_info.Enterprise_Name"
                    placeholder="请输入企业全称"
                  ></el-input>
                  <text v-if="show" class="text-danger font-sm"
                    >该企业已被注册</text
                  >
                </el-form-item>
                <el-form-item label="统一社会信用代码" prop="Tax_Number">
                  <el-input
                    v-model="enterprise_info.Tax_Number"
                    placeholder="请输入统一社会信用代码"
                  ></el-input>
                </el-form-item>
                <el-form-item label="企业地址">
                  <el-cascader
                    placeholder="请选择企业地址"
                    v-model="address"
                    style="width: 80%"
                    :options="Address"
                    :props="{
                      expandTrigger: 'hover',
                      label: 'text',
                      value: 'text',
                      children: 'children',
                    }"
                  ></el-cascader>
                </el-form-item>
                <el-form-item label="公司详细地址" prop="Enterprise_Address">
                  <el-input
                    v-model="enterprise_info.Enterprise_Address"
                    placeholder="请输入公司详细地址"
                  ></el-input>
                </el-form-item>
                <el-form-item>
                  <el-button type="success" @click="previous">上一页</el-button>
                  <el-button type="primary" @click="submitForm('form1')"
                    >下一步</el-button
                  >
                </el-form-item>
              </el-form>
            </el-tab-pane>
            <!--  -->
            <el-tab-pane label="银行账户信息" name="second">
              <el-form
                ref="form2"
                :rules="rules2"
                :model="enterprise_info.Children.enterprise_account[0]"
                label-width="100px"
              >
                <el-form-item label="开户名" prop="Account_Name">
                  <el-input
                    v-model="
                      enterprise_info.Children.enterprise_account[0]
                        .Account_Name
                    "
                    placeholder="请输入开户名"
                  ></el-input>
                  <text class="tex"
                    >需要使用当前实名认证信息对应的收款账号</text
                  >
                </el-form-item>
                <el-form-item label="开户行">
                  <el-cascader
                    v-model="bank"
                    style="width: 80%"
                    :options="Banks"
                    :props="{
                      expandTrigger: 'hover',
                      label: 'name',
                      value: 'name',
                    }"
                    placeholder="请选择开户行"
                  ></el-cascader>
                </el-form-item>
                <el-form-item label="银行账号" prop="Account_Number">
                  <el-input
                    v-model="
                      enterprise_info.Children.enterprise_account[0]
                        .Account_Number
                    "
                    placeholder="请输入银行账号"
                  ></el-input>
                </el-form-item>
                <el-form-item>
                  <el-button type="primary" @click="previousPage(1)"
                    >上一步</el-button
                  >
                  <el-button type="primary" @click="nextPage('form2')"
                    >下一步</el-button
                  >
                </el-form-item>
              </el-form>
            </el-tab-pane>
            <!--  -->
            <el-tab-pane label="管理员信息" name="third">
              <el-form
                ref="form3"
                :model="enterprise_info.Children.enterprise_legal_person[0]"
                :rules="rules3"
                label-width="150px"
              >
                <el-form-item label="管理员姓名" prop="Legal_Person">
                  <el-input
                    v-model="
                      enterprise_info.Children.enterprise_legal_person[0]
                        .Legal_Person
                    "
                    placeholder="请输入管理员姓名"
                  ></el-input>
                </el-form-item>
                <el-form-item label="管理员手机号" prop="Mobile">
                  <el-input
                    v-model="
                      enterprise_info.Children.enterprise_legal_person[0].Mobile
                    "
                    placeholder="请输入管理员手机号"
                  ></el-input>
                </el-form-item>
                <el-form-item label="手机短信验证码" prop="Code">
                  <view class="flex align-center">
                    <el-input
                      v-model="
                        enterprise_info.Children.enterprise_legal_person[0].Code
                      "
                      placeholder="请输入手机短信验证码"
                    ></el-input>
                    <el-button v-if="time" @click="sendMessage()" type="success"
                      >获取验证码</el-button
                    >
                    <el-button v-else type="success">{{ secend }}</el-button>
                  </view>
                </el-form-item>
                <el-form-item label="管理员证件类型" prop="IDType">
                  <el-select
                    v-model="
                      enterprise_info.Children.enterprise_legal_person[0].IDType
                    "
                    placeholder="请选择证件类型"
                  >
                    <el-option label="身份证" value="1"></el-option>
                    <el-option
                      label="香港居民往来内地通行证"
                      value="2"
                    ></el-option>
                    <el-option
                      label="澳门居民往来内地通行证"
                      value="3"
                    ></el-option>
                    <el-option label="护照" value="4"></el-option>
                  </el-select>
                </el-form-item>
                <el-form-item
                  v-if="
                    enterprise_info.Children.enterprise_legal_person[0]
                      .IDType == '1'
                  "
                  prop="ID_Number"
                >
                  <uni-file-picker
                    style="width: 800rpx"
                    @select="Imgselect1"
                    limit="2"
                    title="请上传身份证正反面"
                  ></uni-file-picker>
                </el-form-item>
                <el-form-item label="管理员证件号码" prop="ID_Number">
                  <el-input
                    v-model="
                      enterprise_info.Children.enterprise_legal_person[0]
                        .ID_Number
                    "
                    placeholder="请输入管理员证件号码"
                  ></el-input>
                </el-form-item>
                <el-form-item>
                  <el-button type="primary" @click="previousPage(2)"
                    >上一页</el-button
                  >
                  <el-button
                    :loading="loading"
                    type="primary"
                    @click="submitForm2('form3')"
                    >提交</el-button
                  >
                </el-form-item>
              </el-form>
            </el-tab-pane>
            <!--  -->
          </el-tabs>
        </view>
        <!-- 消息提示 -->
        <view class="content2-2" v-show="active == 1 && type_index == 2">
          <el-result
            icon="success"
            title="成功提示"
            subTitle="认证审核中请等待"
          >
            <template slot="extra">
              <el-button @click="back()" type="primary" size="medium"
                >返回首页</el-button
              >
            </template>
          </el-result>
        </view>
      </view>
      <view class="foot" v-show="active == 0">
        <el-button type="success" @click="next">下一步 </el-button>
      </view>
    </view>
    <!-- 底部 -->
    <yFooter :screenWidth="screenWidth"></yFooter>
  </view>
</template>

<script>
const app = getApp();
import { pathToBase64, base64ToPath } from "@/static/js/Base64.js";
import yHeader from "@/components/yHeader.vue";
import yFooter from "@/components/yFooter.vue";
import { Message } from "element-ui";
import {
  BusinessPIC,
  getAddAction,
  getEditAction,
  CheckRegisterAction,
  GoodsInquiryKeyOriginal,
  getInquiryIDOriginal,
  parseIDCardAction,
} from "@/api/global.js";
import { CityData } from "@/static/js/city.js";
import compressor from "@/static/js/compressor.js";
const { Address } = CityData();
import { nowtime } from "@/static/js/utils.js";
export default {
  components: {
    yHeader,
    yFooter,
  },
  data() {
    return {
      Phone: "",
      code: "",
      screenWidth: uni.getSystemInfoSync().windowWidth,
      screenHigth: uni.getSystemInfoSync().windowHeight,
      ThemeColors: app.globalData.ThemeColors,
      Domain_Business: app.globalData.Domain_Business,
      Domain_IMG: app.globalData.Domain_IMG,
      isActive: false,
      type_index: null,
      active: 0,
      active1: 0,
      show: false,
      activeName: "first",
      activeIndex: 1,
      loading: false,
      address: [],
      Address: Address(),
      formData1: {},
      timer: null,
      time: true,
      secend: 60,
      RandomCode: "",
      bank: [],
      Banks: [
        {
          id: 1,
          abbr: "CCB",
          name: "中国建设银行",
        },
        {
          id: 2,
          abbr: "ICBC",
          name: "中国工商银行",
        },
        {
          id: 3,
          abbr: "ABC",
          name: "中国农业银行",
        },
        {
          id: 4,
          abbr: "BOC",
          name: "中国银行",
        },
        {
          id: 5,
          abbr: "COMM",
          name: "交通银行",
        },
        {
          id: 6,
          abbr: "PSBC",
          name: "中国邮政储蓄银行",
        },
        {
          id: 7,
          abbr: "CMB",
          name: "招商银行",
        },
        {
          id: 8,
          abbr: "CMBC",
          name: "中国民生银行",
        },
        {
          id: 9,
          abbr: "SPDB",
          name: "浦发银行",
        },
        {
          id: 10,
          abbr: "CITIC",
          name: "中信银行",
        },
        {
          id: 11,
          abbr: "CEB",
          name: "中国光大银行",
        },
        {
          id: 12,
          abbr: "HXBANK",
          name: "华夏银行",
        },
        {
          id: 13,
          abbr: "GDB",
          name: "广发银行",
        },
        {
          id: 14,
          abbr: "CIB",
          name: "兴业银行",
        },
        {
          id: 15,
          abbr: "SPABANK",
          name: "平安银行",
        },
        {
          id: 16,
          abbr: "EGBANK",
          name: "恒丰银行",
        },
      ],
      enterprise_info: {
        //提交的表单
        Enterprise_Info_SerialNumber: "", //主键
        Enterprise_Name: "", //企业名称
        Industry_SubCategory_SerialNumber: "101000000000001",
        Industry_Category_SerialNumber: "100000000000001",
        Enterprise_Address: "", //企业注册地址
        Postal_Code: "", //邮政编号
        Tax_Number: "", //营业执照注册号
        Enterprise_Phone: "", //企业电话
        Enterprise_Contacts: "", //企业联系人
        Enterprise_Contacts_Mobile: "", //企业手机号
        Enterprise_Type: 1,
        Row_Status: 1,
        Picture_URL: "",
        E_Mail: "", //电子邮箱
        Children: {
          enterprise_legal_person: [
            {
              Enterprise_Legal_Person_SerialNumber: "",
              Enterprise_Info_SerialNumoer: "",
              Legal_Person: "", //法人姓名
              ID_Number: "", //法人身份证号
              Mobile: "", //法人手机号
              IDType: "", //证件类型
              ParseIDCard_Front: "", //身份证正面
              ParseIDCard_Back: "", //身份证背面
              Code: "", //手机号验证码
            },
          ],
          enterprise_account: [
            {
              Enterprise_Account_SerialNumber: "",
              Enterprise_Info_SerialNumoer: "",
              Bank_Name: "", //开户行
              Account_Name: "", //开户名
              Account_Number: "", //银行账号
            },
          ],
        },
      },
      user_info: {},
      rules1: {
        // 企业姓名
        Enterprise_Name: [
          {
            required: true,
            message: "请输入公司名称",
            trigger: "blur",
          },
          {
            min: 2,
            max: 50,
            message: "密码长度应在 6 到 10 个字符",
            trigger: "blur",
          },
        ],
        //营业执照号
        Tax_Number: [
          {
            required: true,
            message: "请输入营业执照号",
            trigger: "blur",
          },
        ],
        //企业logo图片
        Picture_URL: [
          {
            required: true,
            message: "请上传企业营业执照",
            trigger: "change",
          },
        ],
        //企业详细地址
        Enterprise_Address: [
          {
            required: true,
            message: "请输入企业详细地址",
            trigger: "blur",
          },
        ],
        //电子邮箱
        E_Mail: [
          {
            required: true,
            message: "请输入电子邮箱",
            trigger: "blur",
          },
        ],
        Mobile: [
          {
            required: true,
            message: "请输入手机号",
            trigger: "blur",
          },
          {
            pattern: /^1[3456789]\d{9}$/,
            message: "手机号码格式不正确",
            trigger: "blur",
          },
        ],
      },
      rules2: {
        //银行开户名
        Account_Name: [
          {
            required: true,
            message: "请输入银行开户名",
            trigger: "blur",
          },
        ],
        // 开户行
        Bank_Name: [
          {
            required: true,
            message: "请选择开户行",
            trigger: "change",
          },
        ],
        Account_Number: [
          {
            required: true,
            message: "请输入银行账号",
            trigger: "blur",
          },
        ],
      },
      rules3: {
        //管理员姓名
        Legal_Person: [
          {
            required: true,
            message: "请输入管理员姓名",
            trigger: "blur",
          },
        ],
        // 管理员证件号
        ID_Number: [
          {
            required: true,
            message: "请输入管理员证件号",
            trigger: "blur",
          },
        ],
        //管理员手机号
        Mobile: [
          {
            required: true,
            message: "请输入管理员手机号",
            trigger: "blur",
          },
          {
            pattern: /^1[3456789]\d{9}$/,
            message: "手机号码格式不正确",
            trigger: "blur",
          },
        ],
        //管理员证件类型
        IDType: [
          {
            required: true,
            message: "请选择管理员证件类型",
            trigger: "change",
          },
        ],
        //手机号验证码
        Code: [
          {
            required: true,
            message: "请输入手机号验证码",
            trigger: "blur",
          },
          {
            min: 6,
            message: "短信验证码为6位有效数字",
            trigger: "blur",
          },
        ],
      },
      imageUrl: "", //临时图片路径
      imageUrl2: "", // 临时图片路径
      dialogVisible: false,
      src: "", //临时图片路径
    };
  },
  onLoad() {
    this.enterprise_info.Children.enterprise_legal_person[0].Mobile =
      uni.getStorageSync("loginInfo").use;
  },
  methods: {
    //查看图片
    handlePictureCardPreview(file) {
      this.dialogVisible = true;
      this.dialogImageUrl = file;
    },
    //删除图片
    handleRemove(type, index) {
      if (type === "front") {
        this.form.pic = "";
      } else if (type === "banner") {
        this.fileList = this.fileList.filter(function (item) {
          return item.Picture_Order != index;
        });
      } else if (type === "details") {
        this.fileList1 = this.fileList1.filter(function (item) {
          return item.Picture_Order != index;
        });
      } else if (type === "barcode") {
        this.fileList2 = this.fileList2.filter(function (item) {
          return item.Picture_Order != index;
        });
      } else if (type === "Specifications") {
        console.log(this.form.Children.article_specifications[0]);
        this.form.Children.article_specifications[0].Picture_URL = "";
      }
    },

    handleTabs(url) {
      uni.navigateTo({
        url,
      });
    },

    handleClick(tab, event) {
      console.log(tab.index);
    },

    blur() {
      if (this.enterprise_info.Enterprise_Name) {
        this.CheckEnterprise(this.enterprise_info.Enterprise_Name);
      }
    },

    //选择商户类型
    type_method(index) {
      this.activeIndex = index;
    },

    //营业执照校验
    business_license(file) {
      if (file.size > 2000000) {
        Message({
          type: "error",
          message: "上传图片过大",
        });
        return;
      }
      if (file.size < 5000) {
        Message({
          type: "error",
          message: "上传图片过小",
        });
        return;
      }
      const _this = this;
      new compressor(file, {
        quality: 1,
        success(file) {
          const formData = new FormData();
          formData.append("file", file, file.name);
          let oFileReader = new FileReader();
          oFileReader.readAsDataURL(file);
          oFileReader.onload = function (e) {
            _this.uploadImg(e.target.result, file.name);
          };
        },
        error(err) {
          console.log(err.message);
        },
      });
    },

    //营业执照
    async uploadImg(Data, FileName) {
      uni.showLoading({
        title: "图片解析中",
      });
      let data = {
        Data,
        FileName,
      };
      const res = await BusinessPIC({
        data,
      });
      uni.hideLoading();
      if (res.redirect && res.redirect == "REDIRECT") {
        uni.navigateTo({
          url: "/pages/login/login",
        });
      } else if (res.Status == "success") {
        console.log(res);
        this.enterprise_info.Enterprise_Name = res.Data.Enterprise_Name;
        this.CheckEnterprise(this.enterprise_info.Enterprise_Name);
        this.enterprise_info.Tax_Number = res.Data.Tax_Number;
        this.enterprise_info.Picture_URL = res.Picture_Url;
        this.enterprise_info.Children.enterprise_legal_person[0].Legal_Person =
          res.Data.Legal_Person;
        this.src = res.Picture_Url;
        console.log(res.Picture_Url);
        console.log(this.src);
        console.log(this.enterprise_info);
      }
    },

    //身份证正面
    ID_card_front(file) {
      if (file.size > 2000000) {
        Message({
          type: "error",
          message: "上传图片过大",
        });
        return;
      }
      if (file.size < 5000) {
        Message({
          type: "error",
          message: "上传图片过小",
        });
        return;
      }
      const _this = this;
      new compressor(file, {
        quality: 1,
        success(file) {
          const formData = new FormData();
          formData.append("file", file, file.name);
          let oFileReader = new FileReader();
          oFileReader.readAsDataURL(file);
          oFileReader.onload = function (e) {
            _this.uploadImg1(e.target.result, file.name);
            _this.imageUrl = e.target.result;
          };
        },
        error(err) {
          console.log(err.message);
        },
      });
    },

    //身份证反面
    ID_card_opposite(file) {
      if (file.size > 2000000) {
        Message({
          type: "error",
          message: "上传图片过大",
        });
        return;
      }
      if (file.size < 5000) {
        Message({
          type: "error",
          message: "上传图片过小",
        });
        return;
      }
      const _this = this;
      new compressor(file, {
        quality: 1,
        success(file) {
          const formData = new FormData();
          formData.append("file", file, file.name);
          let oFileReader = new FileReader();
          oFileReader.readAsDataURL(file);
          oFileReader.onload = function (e) {
            _this.uploadImg1(e.target.result, file.name);
            _this.imageUrl2 = e.target.result;
          };
        },
        error(err) {
          console.log(err.message);
        },
      });
    },

    //身份证
    async uploadImg1(Data, FileName) {
      uni.showLoading({
        title: "图片解析中",
      });
      let data = {
        Data,
        FileName,
      };
      console.log(data);
      const res = await parseIDCardAction({
        data,
      });
      console.log(res);
      uni.hideLoading();
      if (res.redirect && res.redirect == "REDIRECT") {
        uni.navigateTo({
          url: "/pages/login/login",
        });
      } else if (res.Status == "success") {
        console.log(res);
        if (res.ID_Number) {
          this.enterprise_info.Children.enterprise_legal_person[0].IDType = "1";
          this.enterprise_info.Children.enterprise_legal_person[0].ID_Number =
            res.ID_Number;
          this.enterprise_info.Children.enterprise_legal_person[0].Legal_Person =
            res.name;
          this.enterprise_info.Enterprise_Address = res.address;
          this.enterprise_info.Children.enterprise_legal_person[0].ParseIDCard_Front =
            Data;
        } else {
          this.enterprise_info.Children.enterprise_legal_person[0].ParseIDCard_Back =
            Data;
        }
      }
    },

    //身份证
    submitForm3(formName) {
      console.log(this.enterprise_info);
      if (
        this.enterprise_info.Children.enterprise_legal_person[0].IDType == "" ||
        this.enterprise_info.Children.enterprise_legal_person[0].Legal_Person ==
          "" ||
        this.enterprise_info.Children.enterprise_legal_person[0].ID_Number ==
          "" ||
        // this.enterprise_info.Picture_URL == "" ||
        this.enterprise_info.Children.enterprise_legal_person[0]
          .ParseIDCard_Front == "" ||
        this.enterprise_info.Children.enterprise_legal_person[0]
          .ParseIDCard_Back == ""
      ) {
        this.active1 = 1;
        this.activeName = "first";
        Message({
          type: "warning",
          message: "请先按步骤填写实名信息",
        });
        return;
      }
      this.enterprise_info.Children.enterprise_account[0].Bank_Name =
        this.bank[0];
      if (
        this.enterprise_info.Children.enterprise_account[0].Account_Name ==
          "" ||
        this.enterprise_info.Children.enterprise_account[0].Bank_Name == "" ||
        this.enterprise_info.Account_Number == ""
      ) {
        this.active1 = 1;
        this.activeName = "second";
        Message({
          type: "warning",
          message: "请先按步骤填写银行账户信息",
        });
        return;
      }
      if (this.enterprise_info.E_Mail == "") {
        Message({
          type: "error",
          message: "请输入邮箱",
        });
        return;
      }
      if (this.RandomCode == "") {
        Message({
          type: "error",
          message: "请先点击发送获取验证码",
        });
        return;
      }
      if (
        this.RandomCode !=
        this.enterprise_info.Children.enterprise_legal_person[0].Code
      ) {
        Message({
          type: "error",
          message: "您输入的短信验证码有误!",
        });
        return;
      }
      this.$refs[formName].validate((valid) => {
        if (valid) {
          let data = {
            Primary_Key_Name: "User_Number", //主键名
            Primary_Key: uni.getStorageSync("loginInfo").use,
            Data: "system_user_info",
            isNullEnterprise: true,
          };
          this.getOriginal(data, 0);
        } else {
          Message({
            type: "error",
            message: "请检查页面表单是否填写或填写不正确",
          });
        }
      });
    },

    async CheckEnterprise(Enterprise_Name) {
      const res = await CheckRegisterAction({
        data: {
          Enterprise_Name,
        },
      });
      if (res.redirect && res.redirect == "REDIRECT") {
        Message({
          message: "登录超时,请重新登录",
          type: "error",
        });
        setTimeout(function () {
          uni.navigateTo({
            url: "/pages/login/login",
          });
        }, 2000);
      } else if (res.Status == "success") {
        this.show = false;
      } else {
        this.show = true;
      }
    },

    nextPage(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          if (this.enterprise_info.Picture_URL == "") {
            Message({
              type: "error",
              message: "请上传企业营业执照",
            });
            return;
          }
          if (this.show) {
            Message({
              type: "error",
              message: "您要认证的企业已被认证",
            });
            return;
          }
          this.enterprise_info.Enterprise_Address =
            this.address[0] +
            this.address[1] +
            this.address[2] +
            this.enterprise_info.Enterprise_Address;
          this.activeName = "second";
        } else {
          Message({
            type: "error",
            message: "请检查页面表单是否填写正确或有未填写项",
          });
        }
      });
      this.activeName = "third";
    },

    nextPage1(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.activeName = "third";
        } else {
          Message({
            type: "error",
            message: "请检查页面表单是否填写正确或有未填写项",
          });
        }
      });
    },

    previousPage(i) {
      if (i == 2) {
        this.activeName = "second";
      } else {
        this.activeName = "first";
      }
    },

    next() {
      this.type_index = this.activeIndex;
      this.active = 1;
      this.active1 = 1;
    },

    previous() {
      this.active = 0;
    },

    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          if (this.enterprise_info.Picture_URL == "") {
            Message({
              type: "error",
              message: "请上传企业营业执照",
            });
            return;
          }
          if (this.show) {
            Message({
              type: "error",
              message: "您要认证的企业已被认证",
            });
            return;
          }
          this.enterprise_info.Enterprise_Address =
            this.address[0] +
            this.address[1] +
            this.address[2] +
            this.enterprise_info.Enterprise_Address;
          this.activeName = "second";
        } else {
          Message({
            type: "error",
            message: "请检查页面表单是否填写正确或有未填写项",
          });
        }
      });
    },

    submitForm1(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          // if (this.enterprise_info.Picture_URL == "") {
          //   Message({
          //     type: "error",
          //     message: "请上传土地资格证",
          //   });
          //   return;
          // }
          if (
            this.enterprise_info.Children.enterprise_legal_person[0]
              .ParseIDCard_Front == ""
          ) {
            Message({
              type: "error",
              message: "请上传身份证正面",
            });
            return;
          }
          if (
            this.enterprise_info.Children.enterprise_legal_person[0]
              .ParseIDCard_Back == ""
          ) {
            Message({
              type: "error",
              message: "请上传身份证背面",
            });
            return;
          }
          this.activeName = "second";
        } else {
          Message({
            type: "error",
            message: "请检查页面表单是否填写正确或有未填写项",
          });
        }
      });
    },

    sendMessage(i) {
      if (
        this.enterprise_info.Children.enterprise_legal_person[0].Mobile == ""
      ) {
        Message.error("请先输入正确的手机号再点击发送");
        return;
      }
      const reg = /^1[3-9]\d{9}$/;
      if (
        !reg.test(
          this.enterprise_info.Children.enterprise_legal_person[0].Mobile
        )
      ) {
        Message.error("请检查手机号格式是否正确!");
        return;
      }
      this.time = false;
      this.secend = 60;
      this.secend--;
      this.timer = setInterval(() => {
        if (this.secend == "01") {
          clearInterval(this.timer);
          // this.RandomCode = ''
          this.time = true;
          return;
        }
        this.secend--;
        if (this.secend < 10) {
          this.secend = "0" + this.secend;
        }
      }, 1000);
      let code = "";
      for (let i = 0; i < 6; i++) {
        code += parseInt(Math.random() * 10);
      }
      this.RandomCode = code;
      uniCloud
        .callFunction({
          name: "sendSms", //对应的云函数名
          data: {
            phone:
              this.enterprise_info.Children.enterprise_legal_person[0].Mobile,
            data: {
              name: "众菌联",
              code: this.RandomCode, //随机生成的验证码，如123456
              action: "注册", //校验类型为“注册”
              expMinute: "5", //短信的有效期，5分钟
            },
          },
        })
        .then((res) => {
          if (res.success) {
            Message.success("短信已发送");
          }
        })
        .catch((msg) => {
          console.log(msg);
          Message.error("系统错误!请稍后重试");
        });
    },
    //企业认证
    submitForm2(formName) {
      if (
        this.enterprise_info.Enterprise_Name == "" ||
        this.enterprise_info.Enterprise_Address == "" ||
        this.enterprise_info.Tax_Number == "" ||
        this.enterprise_info.Picture_URL == ""
      ) {
        this.active1 = 1;
        this.activeName = "first";
        Message({
          type: "warning",
          message: "请先按步骤填写企业信息",
        });
        return;
      }
      this.enterprise_info.Children.enterprise_account[0].Bank_Name =
        this.bank[0];
      if (
        this.enterprise_info.Children.enterprise_account[0].Account_Name ==
          "" ||
        this.enterprise_info.Children.enterprise_account[0].Bank_Name == "" ||
        this.enterprise_info.Account_Number == ""
      ) {
        this.active1 = 1;
        this.activeName = "second";
        Message({
          type: "warning",
          message: "请先按步骤填写银行账户信息",
        });
        return;
      }
      if (this.RandomCode == "") {
        Message({
          type: "error",
          message: "请先点击发送获取验证码",
        });
        return;
      }
      if (
        this.RandomCode !=
        this.enterprise_info.Children.enterprise_legal_person[0].Code
      ) {
        Message({
          type: "error",
          message: "您输入的短信验证码有误!",
        });
        return;
      }
      if (
        this.enterprise_info.Children.enterprise_legal_person[0].IDType == "1"
      ) {
        if (
          this.enterprise_info.Children.enterprise_legal_person[0]
            .ParseIDCard_Front == "" ||
          this.enterprise_info.Children.enterprise_legal_person[0]
            .ParseIDCard_Back == ""
        ) {
          return;
        }
      }
      this.$refs[formName].validate((valid) => {
        if (valid) {
          let data = {
            Primary_Key_Name: "User_Number", //主键名
            Primary_Key: uni.getStorageSync("loginInfo").use,
            Data: "system_user_info",
            isNullEnterprise: true,
          };
          this.getOriginal(data, 1);
        } else {
          Message({
            type: "error",
            message: "请检查页面表单是否填写或填写不正确",
          });
        }
      });
    },

    async getOriginal(data, i) {
      this.loading = true;
      const res = await getInquiryIDOriginal({
        data,
      });
      if (res.redirect && res.redirect == "REDIRECT") {
        uni.navigateTo({
          url: "/pages/login/login",
        });
      }
      this.user_info = res[0];
      let Data = {
        Data: JSON.stringify({
          enterprise_info: [this.enterprise_info],
        }),
      };
      this.getAdd(Data, i);
    },

    async getAdd(data, i) {
      const res = await getAddAction({
        data,
      });
      this.loading = false;
      if (res.redirect && res.redirect == "REDIRECT") {
        uni.navigateTo({
          url: "/pages/login/login",
        });
      } else if (res.Status == "success") {
        this.user_info.Authentication_Type = i;
        this.user_info.Admin_Type = 1;
        this.user_info.Enterprise_Info_SerialNumber = res.Data;
        this.user_info.Authentication_Date = nowtime();
        let Data = {
          Data: JSON.stringify({
            Modify: {
              system_user_info: [this.user_info],
            },
          }),
          token: uni.getStorageSync("loginInfo").token,
        };
        this.getEdit(Data);
      } else {
        this.loading = false;
        Message({
          type: "error",
          message: "系统错误",
        });
      }
    },

    async getEdit(data) {
      const res = await getEditAction({
        data,
      });
      this.loading = false;
      if (res.redirect && res.redirect == "REDIRECT") {
        uni.navigateTo({
          url: "/pages/login/login",
        });
      } else if (res.Status == "success") {
        Message({
          type: "success",
          message: "认证审核中",
        });
        this.active1 = 2;
        this.type_index = 2;
      }
    },

    back() {
      uni.navigateTo({
        url: "/pages/index/index",
      });
    },
  },
};
</script>

<style lang="scss" scoped>
//element上传样式
.avatar-uploader .el-upload {
  border: 1px dashed #d9d9d9;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}
.avatar-uploader .el-upload:hover {
  border-color: #409eff;
}
.avatar-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  width: 178px;
  height: 178px;
  line-height: 178px;
  text-align: center;
}
.avatar {
  width: 178px;
  height: 178px;
  display: block;
}
.authorized {
  // height: 100%;
  margin: 0 auto;
  box-sizing: border-box;

  .foot {
    text-align: center;

    // .btns {
    //   background: #28a745;
    // }
    .btns :hover {
      background: #28a745;
    }
  }

  .content {
    width: 1440rpx;
    margin: 0 auto;
    box-sizing: border-box;

    .content1 {
      width: 100%;
      display: flex;

      .item {
        width: 580rpx;
        margin-left: 30rpx;
        border: 1px solid #ebebeb;
        cursor: pointer;
        display: flex;
        padding: 20rpx;
        box-sizing: border-box;

        .img {
          display: flex;
          align-items: center;

          image {
            width: 100rpx;
            height: 100rpx;
          }
        }

        .item_text {
          font-size: 28rpx;
          display: flex;
          flex-direction: column;

          p {
            padding: 0 0 0 10rpx;
            margin: 10rpx 0 0 0;
          }
        }
      }

      .active {
        width: 580rpx;
        height: 100%;
        margin-left: 30rpx;
        border: 1px solid #ebebeb;
        cursor: pointer;
        display: flex;
        padding: 20rpx;
        box-sizing: border-box;

        .img {
          display: flex;
          align-items: center;

          image {
            width: 100rpx;
            height: 100rpx;
          }
        }

        .item_text {
          font-size: 28rpx;
          display: flex;
          flex-direction: column;

          p {
            padding: 0 0 0 10rpx;
            margin: 10rpx 0 0 0;
          }
        }

        border: 1px solid #28a745;
      }
    }

    .content2-2 {
      .tex {
        font-size: 24rpx;
      }
    }
  }
}
</style>